﻿using B.S.Databasic.Api.Wrter.Application.Command.Account;
using B.S.Databasic.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Databasic.Api.Wrter.Controllers
{
    /// <summary>
    /// 用户控制器(写)
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AccountController : ControllerBase
    {
        private readonly IMediator mediator;

        public AccountController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 用户新增
        /// </summary>
        /// <param name="request">实体命令</param>
        /// <returns>返回统一封装类</returns>
        [HttpPost]
        [Authorize]
        public async Task<ApiResult<int>> AddAccount(AddAccountCommand request)
        {
            var result = await mediator.Send(request);
            return result;
        }
        /// <summary>
        /// 用户删除
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回统一包装类</returns>
        [HttpDelete]
        [Authorize]
        public async Task<ApiResult<int>> DeleteAccount([FromQuery] DeleteAccountCommand request)
        {
            var result = await mediator.Send(request);
            return result;
        }
        /// <summary>
        /// 用户修改
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回统一包装类</returns>
        [HttpPut]
        [Authorize]
        public async Task<ApiResult<int>> UpdateAccount(UpdateAccountCommand request)
        {
            var reslut = await mediator.Send(request);
            return reslut;
        }
        /// <summary>
        /// 修改用户状态状态
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回统一包装类</returns>
        [HttpPut]
        [Authorize]
        public async Task<ApiResult<int>> UpdateAccountState([FromQuery] UpdateAccountStateCommand request)
        {
            var reslut = await mediator.Send(request);
            return reslut;
        }
    }
}
